import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
// import whoami from '@feidao/web/atom/browser/msg/whoami';
import s_get from '@dfeidao/atom-web/storage/get';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';

import P03 from './P03';
import P04 from './P04';
import P05 from './P05';


import get from '@dfeidao/atom-web/local/get';
interface Users {
	page_no: number;
	page_size: number;
	dataArray: object[];
	count: number;
}

export default async function a011(fd: IFeidaoAiBrowserComponent) {

	const page_no = get(fd, 'page_no') as number;
	const page_size = get(fd, 'page_size');
	// const user = await whoami(get_user_info);
	const productid = await s_get('productid');
	const client_type = get(fd, 'client_type');
	const select1 = fd.data.node.querySelector<HTMLSelectElement>('[data-name="group_number"]');
	const index = select1.options.selectedIndex;
	const group_number = select1.options[index].value;

	const res = await nodejs<Users>('menu/zj-000004/s001', {
		productid, page_no, page_size, client_type, group_number
	});
	if (res.count === 0) {
		render(fd, '', P03, 'P03', 'inner');
		render(fd, '', P04, 'P04', 'inner');
		fd.data.node.querySelector('[data-feidao-pdaentation="P05"]').innerHTML = '';
	} else if (res.count < 10) {
		render(fd, res.dataArray, P03, 'P03', 'inner');
		fd.data.node.querySelector('[data-feidao-presentation="P05"]').innerHTML = '';
		fd.data.node.querySelector('[data-feidao-presentation="P04"]').innerHTML = '';
	} else {
		render(fd, res.dataArray, P03, 'P03', 'inner');
		res.page_no = page_no;
		render(fd, res, P05, 'P05', 'inner');
		fd.data.node.querySelector('[data-feidao-presentation="P04"]').innerHTML = '';
	}
}
